<!-- 我的车位-提交车位申请 -->

<template>
	<view>
		<view class="content">
			<view class="block__title">基本信息</view>

			<view class="cu-form-group">
				<view class="title">小区</view>
				{{plotNum}}
			</view>

			<view class="cu-form-group">
				<view class="title">申请人姓名</view>
				{{submitter}}
			</view>


			<view class="cu-form-group">
				<view class="title">车位编号</view>
				<picker bindchange="PickerChange" :value="parkIndex" :range="parkScopes" :range-key="'num'"
					@change="chooseCarPosition">
					<view class="picker">
						{{parkScopes[parkIndex].num?parkScopes[parkIndex].num:'请选择'}}
					</view>
				</picker>
			</view>

<!-- 			<view class="cu-form-group">
				<view class="title">车牌号</view>
				<input v-model="licensePlateNumber" style="text-align:right" placeholder="请输入"></input>
			</view> -->

			<view class="cu-form-group">
				<view class="title">车位类型</view>
				<picker bindchange="PickerChange" :value="carType" :range="carTypes" :range-key="'carTypeName'" @change="chooseCarTypes">
					<view class="picker">
						{{carTypes[carType].carTypeName?carTypes[carType].carTypeName:'请选择'}}
					</view>
				</picker>
			</view>


		</view>
		<!-- 		<view class="content_box" v-if="homeMemberType == applyPersonId">
			<button @click="submitApply()" type="primary">提交申请</button>
		</view> -->
		<view class="content_box">
			<button @click="submitApply()" type="primary">提交申请</button>
		</view>
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js'
	const constant = context.constant;
	import {
		getCurCommunity
	} from '../../api/community/communityApi.js'

	import {
		getProperty
	} from '../../api/property/propertyApi.js'


	export default {
		data() {
			return {
				plotNum:'', //小区名
				plotCommunityId:'',  //小区id
				parkIndex: "", //默认车位
				licensePlateNumber: '',
				carTypeData:"",
				psId:'',
				num:'',

				parkScopes: [],
				owner: '张三',
				carType: '',
				carNum: '',
				carColor: '',
				ownerId: '',
				userId: '',
				applyPersonName: '',
				applyPersonLink: '',
				applyPersonId: '',
				parkingSpaces: [],
				parkingSpaceIds: [],
				parkingSpacesName: '',
				//车辆类型
				carTypes: [
					{
						carTypeName: '产权'
					},
					{
						carTypeName: '租赁'
					}
				],

				communityId: 0,
				examineObjectId: 0,
				examineObjectName: "",
				examineType: "",
				proprietorId: 0,
				submitter: "",
			};
		},
		onLoad: function(options) {
			let _this = this;
			let userName = uni.getStorageSync("commonUser");
			_this.submitter = userName.name
			
			let userId = uni.getStorageSync("commonUser");
			this.ownerId = userId.id
			_this.loadCarNumber()
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let _plotNum = uni.getStorageSync("_selectCommunity");
			// this.plotNum = _plotNum.communityName + "小区";
		
			if (_plotNum != null && _plotNum != undefined && _plotNum != '') {
				this.plotNum = _plotNum.communityName + "小区";
				this.plotCommunityId = _plotNum.id; //小区id
				console.log("小区ID", this.plotCommunityId)
				uni.setStorageSync('plotCommunityId',this.plotCommunityId);
			}
		},
		methods: {
			
			// 查询车位
			loadCarNumber(){
				let _that = this;
				let _plotNumData = uni.getStorageSync("_selectCommunity");
				this.plotCommunityId = _plotNumData.id; //小区id
				uni.request({
					url: constant.url.queryCarNum,
					header: context.getHeaders(),
					POST: "GET",
					data: {
						communityId:this.plotCommunityId,
					},
					//动态数据
					success: function(res) {
						console.log("666",res.data); //成功情况下跳转
						_that.parkScopes = res.data.data
							
						// }
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			
			// 车位位置
			chooseCarPosition: function(e) {
				this.parkIndex = e.target.value //取其下标
				this.psId = this.parkScopes[this.parkIndex].psId;
				this.num = this.parkScopes[this.parkIndex].num;
				console.log("this.psId",this.psId,this.num)
				// let selected = this.parkScopes[this.parkIndex] //获取选中的数组
			},

			//车辆类型
			chooseCarTypes: function(e) {
				this.carType = e.target.value;
				// this.carType = Number(Number(this.carTypeData) + 2) 
				// console.log("this.carType",this.carType)
				// this.carTypeCode = this.carTypeCodes[index];
				// this.carTypeName = this.carTypes[this.carType];
			},

			startDateChange: function(e) {
				this.startDate = e.detail.value
			},
			submitApply: function() {
				
				let obj = {

					"communityId": this.plotCommunityId,
					"examineObjectId": this.psId,
					"examineObjectName": this.num,
					"examineType": "车位审批",
					"proprietorId": this.ownerId, // 用户id
					"submitter": this.submitter, //提交人
					"type":1  //1绑定2解绑
				};
				let msg = "";

				if (obj.submitter == "") {
					msg = "请填写申请人姓名";
				}
				if (msg != "") {
					wx.showToast({
						title: msg,
						icon: 'none',
						duration: 2000
					});
					return;
				}
				uni.request({
					url: constant.url.saveOwnerCar,
					header: context.getHeaders(),
					method: "POST",
					data: obj,
					success: function(res) {
						console.log("res车位", res)
						if(res.data.code == 0 || res.data.code == 200){
							uni.redirectTo({
								url: '../parkingInfo/myParking',
							});
							wx.showToast({
								title: "绑定成功",
								icon: 'none',
								duration: 2000
							});
						}else if(res.data.code == 500){
							uni.redirectTo({
								url: '../parkingInfo/myParking',
							});
							wx.showToast({
								title: "该审批对象正在被审批",
								icon: 'none',
								duration: 2000
							});
						}
						
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});




			}
		}
	};
</script>
<style scoped lang="scss">
	.content {
		margin: 20rpx 30rpx;
		height: calc(100vh - 120rpx);
		overflow: auto;
	}

	.content_box {
		display: flex;
		position: absolute;
		bottom: 0rpx;
		width: 100%;
		height: 100rpx;
		justify-content: center;
		align-items: center;

		button {
			width: 400rpx;
			height: 70rpx;
			line-height: 70rpx;
			font-size: 26rpx;
			border-radius: 30rpx;
		}
	}

	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.button_up_blank {
		height: 40rpx;
	}
</style>
